//
//  ComposePictureCell.swift
//  weiboSwift1.0
//
//  Created by xuNick on 16/4/27.
//  Copyright © 2016年 NN. All rights reserved.
//

import UIKit

class ComposePictureCell: UICollectionViewCell {
    
    var delete:(() -> ())?
    
    
    var image:UIImage?{
        didSet{
            
            if image == nil{
                imageView?.image = UIImage(named: "compose_pic_add")
                deleteButton.hidden = true
            }else{
                
                imageView?.image = image
                deleteButton.hidden = false
            }
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setupUI(){
        //添加imageview
        self.contentView.addSubview(imageView!)
        
        imageView?.snp_makeConstraints(closure: { (make) -> Void in
            make.edges.equalTo(self.contentView)
        })
        
        self.contentView.addSubview(deleteButton)
        
        deleteButton.snp_makeConstraints { (make) -> Void in
            make.top.trailing.equalTo(self.contentView)
        }
        
    }
    
    //MARK: -  懒加载控件
    lazy var imageView:UIImageView? = {
       let view = UIImageView()
        
        return view
    }()
    
    lazy var deleteButton:UIButton = {
       let button = UIButton()
        button.setImage(UIImage(named: "tabbar_compose_background_icon_close"), forState: UIControlState.Normal)
        button.sizeToFit()
        //添加监听事件,通知view删除cell
        button.addTarget(self, action: "clickDelete", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        return button
    }()
    
    
    func clickDelete(){
            delete!()
    }
}
